package rdw.robot;

import java.awt.Robot;

/**
 * KeyboardRobot handles the keyboard functions for the RemoteRobot.
 */
public class KeyboardRobot
{
	private Robot robot;
	
	public KeyboardRobot(Robot robot)
	{
		this.robot = robot;
	}
	
	public void keyStroke(char c)
	{
		robot.waitForIdle();

		KeyStroke keyStroke = KeyMapping.getKeyStroke(c);
		int modifiers = keyStroke.getModifierKeyCode();
		int keycode = keyStroke.getKeyCode();
		
		if (modifiers != 0)
		{
			robot.keyPress(modifiers);
		}
		
		robot.keyPress(keycode);
		robot.keyRelease(keycode);
		
		if (modifiers != 0)
		{
			robot.keyRelease(modifiers);
		}
	}
}
